package com.zhimu.activemq_demo.activemq.spring;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.jms.core.JmsTemplate;
import org.springframework.stereotype.Service;

/**
 * @Author: Alvin
 * @Date: 2019/6/23 01:37
 * @Description
 */
@Service
public class SpringMQ_Consumer {

    @Autowired
    private JmsTemplate jmsTemplate;

    public static void main(String[] args) {
        ApplicationContext applicationContext = new ClassPathXmlApplicationContext("applicationContext.xml");

        SpringMQ_Consumer springMQConsumer = (SpringMQ_Consumer) applicationContext.getBean("springMQ_Consumer");
        while (true) {
            String retValue = (String) springMQConsumer.jmsTemplate.receiveAndConvert();
            if (null != retValue) {
                System.out.println("接收到的消息：" + retValue);
            } else {
                break;
            }
        }
    }
}
